import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import PageLayout from '../views/PageLayout.vue'
import About from '../views/About.vue'
import Login from '../components/Login.vue'
import KeepAliveAbout from '../views/KeepAliveAbout.vue'
import KeepFalse from '../views/keep/KeepFalse.vue'
import NotFound from '@/components/NotFound.vue'
import KeepTrue from '@/views/Keep/KeepTrue.vue'
import KeepTrue2 from '@/views/Keep/KeepTrue2.vue'
// interface RouteMeta {
//   keepAlive?: boolean
// }
const routes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/',
    name: 'pageLayout',
    component: PageLayout,
    children: [
      {
        path: '/about',
        name: 'about',
        component: About
      },
      {
        path: '/keepAliveAbout',
        name: 'keepAliveAbout',
        component: KeepAliveAbout,
        // redirect: '/keepAliveAbout/keepFalse', //无效
        children: [
          {
            path: '', // 为空则默认显示
            name: 'keepFalse',
            component: KeepFalse
          },
          {
            path: '/keepAliveAbout/keepTrue',
            name: 'keepTrue',
            components: {
              default: KeepTrue,
              KeepTrue2
            },
            meta: {
              keepAlive: true
            }
          }
        ]
      }
    ]
  },
  {
    name: '404',
    path: '/:notFound(.*)*',
    component: NotFound
  }
]
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
export default router
